import ajax from "../../utils/ajax.js"
import store from "../../store/index.js"
import { todetail } from "../../store/actions/todetail.js"
console.log(store.getState())
const app = getApp()
// pages/classify/classify.js
Page({
  getgoodsinfo(e) {
    let key = e.currentTarget.dataset.id;
    this.data.goodslist.map(items => {
      if (items.id === key) {
        store.dispatch(todetail(items))
      }
    })
    console.log(store.getState().todetail)
    wx.navigateTo({
      url: '../detail/detail',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  switch () {
    this.getgoodslist()
  },
  getsidebarlist () {
    ajax.get('http://www.xiongmaoyouxuan.com/api/tabs?sa=')
      .then(resp => {
        this.setData({
          list:resp.data.data.list
        })
      })
  },
  getgoodslist () {
    ajax.get('http://rap2api.taobao.org/app/mock/86931/steam')
      .then(resp => {
        this.setData({
          goodslist:resp.data.data
        })
      })
  },
  switchRightTab: function (e) {
    // 获取item项的id，和数组的下标值
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    // 把点击到的某一项，设为当前index
    this.setData({
      curNav: id,
      curIndex: index
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    goodslist:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getsidebarlist()
    this.getgoodslist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.setCartcount()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})